//
//  LBContactManager.m
//  LBContactListViewController
//
//  Created by LINAICAI on 2017/12/6.
//

#import "LBContactManager.h"
#import <LBCoreKit/LBService.h>
#import "LBContactModel.h"
#import "LBContactURL.h"
#import <MJExtension/MJExtension.h>
#import <LBCoreKit.h>
@interface LBContactManager ()

@end
@implementation LBContactManager
/**
 可以根据手机号码或者姓名进行模糊查询
 
 @param condition 联系人手机号码或姓名
 @param success   成功回调
 @param fail      失败回调
 */
+ (void)searchContactWithCondition:(NSString *)condition
                           success:(void(^)(NSArray<LBContactModel*> *models))success
                              fail:(void(^)(NSString *message))fail{
    NSDictionary *dic = @{
                          @"condition":condition,
                          };
    [LBService get:LBURL_USER(URL_User_queryContact) params:dic completion:^(LBResponse *response) {
        if (response.succeed) {
            NSArray<LBContactModel*> *models = [LBContactModel mj_objectArrayWithKeyValuesArray:response.data];
            success(models);
        }
        else{
            fail(response.message);
        }
    }];
    
}
/**
 用户删除一个联系人
 
 @param Ids     要删除的联系人id数组
 @param success 成功回调
 @param fail    失败回调
 */
+ (void)deleteContactWithIds:(NSString *)Ids
                     success:(void(^)(NSString *message))success
                        fail:(void(^)(NSString *message))fail
{
    NSDictionary *dic = @{@"ids":Ids};
    [LBService post:LBURL_USER(URL_User_deleteContact) params:dic completion:^(LBResponse *response) {
        if (response.succeed) {
            success(response.message);
        }
        else{
            fail(response.message);
        }
    }];
}
/**
 用户添加一个联系人
 
 @param company     公司
 @param label       职务
 @param mobilePhone 手机号码
 @param name        姓名
 @param success     成功回调
 @param fail        失败回调
 */
+ (void)addContactWithCompany:(NSString *)company
                        lable:(NSString *)lable
                  mobilePhone:(NSString *)mobilePhone
                         name:(NSString *)name
                      success:(void(^)(NSString *message,LBContactModel * model))success
                         fail:(void(^)(NSString *message))fail{
    NSDictionary *dic = @{
                          @"company":LBStringNotNil(company),
                          @"lable":LBStringNotNil(lable),
                          @"mobilePhone":LBStringNotNil(mobilePhone),
                          @"name":LBStringNotNil(name),
                          };
    [LBService post:LBURL_USER(URL_User_addContact) params:dic completion:^(LBResponse *response) {
        if (response.succeed) {
            LBContactModel * model = [LBContactModel mj_objectWithKeyValues:response.data];
            success(response.message,model);
        }
        else{
            fail(response.message);
        }
    }];
}
/**
 用户修改一个联系人
 
 @param Id          联系人标识
 @param company     公司
 @param label       职务
 @param mobilePhone 用户手机号码
 @param name        姓名
 @param success     成功回调
 @param fail        失败回调
 */
+ (void)updateContactWithId:(NSString *)Id
                    company:(NSString *)company
                      lable:(NSString *)lable
                mobilePhone:(NSString *)mobilePhone
                       name:(NSString *)name
                    success:(void(^)(NSString *message))success
                       fail:(void(^)(NSString *message))fail{
    NSDictionary *dic = @{
                          @"id":LBStringNotNil(Id),
                          @"company":LBStringNotNil(company),
                          @"lable":LBStringNotNil(lable),
                          @"mobilePhone":LBStringNotNil(mobilePhone),
                          @"name":LBStringNotNil(name),
                          };
    [LBService post:LBURL_USER(URL_User_updateContact) params:dic completion:^(LBResponse *response) {
        if (response.succeed) {
            success(response.message);
        }
        else{
            fail(response.message);
        }
    }];
}
@end
